<?php 
/**
 * ... ...
 * ... ...
 *
 */ 


JCAT_Package::ImportClass('JCAT_ViewGtk',JCAT::PACKAGE_MVCGTK) ;
JCAT_Package::ImportInterface('JCAT_IViewForm',JCAT::PACKAGE_MVC) ;

define('SQLGROUP_TEXT_LOGIC_AND',JCAT_Language::Sentence('条件组，组内逻辑：与')) ;
define('SQLGROUP_TEXT_LOGIC_OR',JCAT_Language::Sentence('条件组，组内逻辑：或')) ;

/**
 * 视图类 DBTableLinkView 
 *
 * @access public
 */
class DBTableLinkView 
	//<<[UnmodifiableBlock.Start]::Extends And Implements::>>//
	extends JCAT_ViewGtk
	implements JCAT_IViewForm
	//<<[UnmodifiableBlock.End]::Extends And Implements::>>// 
{
	
	/**
	 * 构造函数 
	 *
	 * @access	public
	 * @param	$aParent			JCAT_IViewContainer		视图的父对象(父视图 或 控制器)。注意：视图不应单独存在，必须有一个父对象！ 
	 * @param 	$bTableLink=true	bool					是否使用数据表连接
	 * @return	void
	 */
	public function DBTableLinkView(JCAT_IViewContainer $aParent,$sViewName='DBTableLinkView',$sDataExchangeName='TableLink',$bTableLink=true)
	{
		// 调用父类构造函数 
		$this->JCAT_ViewGtk($sViewName,'template.DBTableLinkView.glade','DBTableLinkView',$aParent) ;

		$this->sDataExchangeName = $sDataExchangeName ;
		$this->bTableLink = $bTableLink ;
		
		$this->Initialize() ;
	}
	
	/**
	 * 初始化 视图 
	 *
	 * @access	protected
	 * @return	void
	 */
	protected function Initialize()
	{
		//<<[UnmodifiableBlock.Start]::UICtrl Children::>>//
		// 载入UI控件
		$sCurrentDirectory = dirname(__FILE__).'/' ;
		JCAT_Package::ImportClass('TreeDBTableLink',$sCurrentDirectory.'Instance.UICtrls/class.TreeDBTableLink.php') ;
		$this->AddUICtrl(new TreeDBTableLink(),$this->sDataExchangeName,'DBTableLink') ;
		//<<[UnmodifiableBlock.End]::UICtrl Children::>>// 
		
		//<<[UnmodifiableBlock.Start]::View Children::>>//

		//<<[UnmodifiableBlock.End]::View Children::>>// 
		
		
		// 在此加入其它初始化代码 
	 	// TODO ... ...

	}
	
	/**
	 * 创建主窗体事件 
	 *
	 * @access	protected
	 * @return	void
	 */
	 protected function OnInitView()
	 {
	 	$wndNewTableLink = $this->GetChildWidget('EntNewTableLink') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($wndNewTableLink) ;
	 	$wndNewTableLink->set_visible($this->bTableLink,false) ;
	 }


	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnNewTableLink()
	 {
	 	$aUICtrl = $this->GetUICtrl('TreeDBTableLink') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($aUICtrl,'JCAT_IUICtrl') ;
	 	
	 	$aDlg = new DBTableLinkDlg($this,array_keys($this->arrTableColumns)) ;
	 	$nResponse = $aDlg->DoDialog() ;
	 	if( $nResponse!=Gtk::RESPONSE_OK )
	 	{
	 		////  测试数据  ////////////////
		 	$arrGroupData[TreeDBTableLink::CLM_EXPRESSION] = '' ;
		 	$arrGroupData[TreeDBTableLink::CLM_LEFT] = 'xxxx' ;
		 	$arrGroupData[TreeDBTableLink::CLM_OPERATOR] = 'JOIN' ;
		 	$arrGroupData[TreeDBTableLink::CLM_RIGHT] = 'yyyy' ;
		 	$arrGroupData[TreeDBTableLink::CLM_RIGHT_B] =  '' ;
		 	$arrGroupData[TreeDBTableLink::CLM_TYPE] =  TreeDBTableLink::TYPE_LINK ;
		 	ksort($arrGroupData);
		 	
		 	$aUICtrl->AppendItem($arrGroupData) ;
		 	///////////////////
	 	
	 		return ;
	 	}
	 	
	 	$arrCellDatas[TreeDBTableLink::CLM_EXPRESSION] = $aDlg->GetExpression() ;
	 	$arrCellDatas[TreeDBTableLink::CLM_TYPE] = TreeDBTableLink::TYPE_LINK ;
	 	$arrCellDatas[TreeDBTableLink::CLM_OPERATOR] = $aDlg->GetJoinType() ;
	 	$arrCellDatas[TreeDBTableLink::CLM_LEFT] = $aDlg->GetTables('Left') ;
	 	$arrCellDatas[TreeDBTableLink::CLM_RIGHT] = $aDlg->GetTables('Right') ;
	 	$arrCellDatas[TreeDBTableLink::CLM_RIGHT_B] = '' ;
	 	ksort($arrCellDatas) ;

	 	$aNewItem = $aUICtrl->AppendItem($arrCellDatas) ;
	 	
	 	
	 	$arrGroupData[TreeDBTableLink::CLM_EXPRESSION] = SQLGROUP_TEXT_LOGIC_AND ;
	 	$arrGroupData[TreeDBTableLink::CLM_LEFT] = '' ;
	 	$arrGroupData[TreeDBTableLink::CLM_OPERATOR] = '' ;
	 	$arrGroupData[TreeDBTableLink::CLM_RIGHT] = '' ;
	 	$arrGroupData[TreeDBTableLink::CLM_RIGHT_B] =  '' ;
	 	$arrGroupData[TreeDBTableLink::CLM_TYPE] =  TreeDBTableLink::TYPE_GROUP ;
	 	ksort($arrGroupData);
	 	
	 	$aUICtrl->AppendItem($arrGroupData,$aNewItem) ;
	 }

	 	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnNewConditionGroup()
	 {
	 	$aUICtrl = $this->GetUICtrl('TreeDBTableLink') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($aUICtrl,'TreeDBTableLink') ;

	 	// selected Item
	 	$aItem = $aUICtrl->GetFirstSelectedItem() ;
	 	
	 	// 在 数据表连接视图中
	 	if( $this->bTableLink )
	 	{
		 	if( !$aItem )
		 	{
		 		return ;
		 	}
		 	
		 	// Item 类型
		 	$nItemType = $aUICtrl->GetCellData($aItem,TreeDBTableLink::CLM_TYPE) ;
		 	
		 	// 
		 	if( !in_array($nItemType,array(TreeDBTableLink::TYPE_LINK,TreeDBTableLink::TYPE_GROUP)) )
		 	{
		 		JCAT_Gtk::MsgDlg(JCAT_Language::Sentence('请选择上级条件组 或 所属的表连接。')) ;
		 		return ;
		 	}
	 	}
	 	
	 	$aGroupData[TreeDBTableLink::CLM_EXPRESSION] = SQLGROUP_TEXT_LOGIC_AND ;
	 	$aGroupData[TreeDBTableLink::CLM_LEFT] = '' ;
	 	$aGroupData[TreeDBTableLink::CLM_OPERATOR] = '' ;
	 	$aGroupData[TreeDBTableLink::CLM_RIGHT] = '' ;
	 	$aGroupData[TreeDBTableLink::CLM_RIGHT_B] =  '' ;
	 	$aGroupData[TreeDBTableLink::CLM_TYPE] =  TreeDBTableLink::TYPE_GROUP ;
	 	ksort($aGroupData);
	 	
	 	$aUICtrl->AppendItem($aGroupData,$aItem) ;
	 }
	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnNewSQLExpression()
	 {
	 	$aUICtrl = $this->GetUICtrl('TreeDBTableLink') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($aUICtrl,'TreeDBTableLink') ;

	 	// selected Item
	 	$aItem = $aUICtrl->GetFirstSelectedItem() ;
	 	if( !$aItem )
	 	{
	 		return ;
	 	}
	 
	 	// Item 类型
	 	$nItemType = $aUICtrl->GetCellData($aItem,TreeDBTableLink::CLM_TYPE) ;
	 	
	 	// 
	 	if( $nItemType!=TreeDBTableLink::TYPE_GROUP )
	 	{
	 		JCAT_Gtk::MsgDlg(JCAT_Language::Sentence('请选择上级条件组。')) ;
	 		return ;
	 	}
	 	
	 	
	 	$aDlg = new SQLExpressionDlg($this,$this->arrTableColumns) ;
	 	$nResponse = $aDlg->DoDialog() ;
	 	if( $nResponse!=Gtk::RESPONSE_OK )
	 	{
	 		return ;
	 	}
	 	
	 	$arrCellDatas[TreeDBTableLink::CLM_EXPRESSION] = $aDlg->GetExpression() ;
	 	$arrCellDatas[TreeDBTableLink::CLM_TYPE] = TreeDBTableLink::TYPE_EXPRESSION ;
	 	$arrCellDatas[TreeDBTableLink::CLM_OPERATOR] = $aDlg->GetOperator() ;
	 	$arrCellDatas[TreeDBTableLink::CLM_LEFT] = $aDlg->GetSide('Left') ;
	 	$arrCellDatas[TreeDBTableLink::CLM_RIGHT] = $aDlg->GetSide('Right') ;
	 	$arrCellDatas[TreeDBTableLink::CLM_RIGHT_B] = $aDlg->GetSide('RightB') ;
	 	ksort($arrCellDatas) ;
	 	
	 	$aUICtrl = $this->GetUICtrl('TreeDBTableLink') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($aUICtrl,'JCAT_IUICtrl') ;
	 	$aUICtrl->AppendItem($arrCellDatas,$aItem) ;
	 }

	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnEidt()
	 {
	 	$aUICtrl = $this->GetUICtrl('TreeDBTableLink') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($aUICtrl,'TreeDBTableLink') ;
	 	
	 	$aItem = $aUICtrl->GetFirstSelectedItem() ;
	 	if(!$aItem)
	 	{
	 		JCAT_Gtk::MsgDlg(JCAT_Language::Sentence('请选择项目')) ;
	 		return ;
	 	}
	 	
	 	// Item 类型
	 	$nItemType = $aUICtrl->GetCellData($aItem,TreeDBTableLink::CLM_TYPE) ;

 		$sLeft = $aUICtrl->GetCellData($aItem,TreeDBTableLink::CLM_LEFT) ;
 		$sRight = $aUICtrl->GetCellData($aItem,TreeDBTableLink::CLM_RIGHT) ;
 		$sRightB = $aUICtrl->GetCellData($aItem,TreeDBTableLink::CLM_RIGHT_B) ;
 		$sOperator = $aUICtrl->GetCellData($aItem,TreeDBTableLink::CLM_OPERATOR) ;
	 	
	 	switch ($nItemType)
	 	{
	 		// 表连接
	 		case TreeDBTableLink::TYPE_LINK :

			 	$aDlg = new DBTableLinkDlg($this,array_keys($this->arrTableColumns),$sLeft,$sRight,$sOperator) ;
			 	$nResponse = $aDlg->DoDialog() ;
			 	if( $nResponse!=Gtk::RESPONSE_OK )
			 	{
			 		return ;
			 	}
	 			
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_OPERATOR,  $aDlg->GetJoinType() ) ;
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_LEFT,  $aDlg->GetTables('Left') ) ;
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_RIGHT,  $aDlg->GetTables('Right') ) ;
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_EXPRESSION,  $aDlg->GetExpression() ) ;

	 			break ;
	 		
	 		case TreeDBTableLink::TYPE_EXPRESSION :
	 	
			 	$aDlg = new SQLExpressionDlg($this,$this->arrTableColumns,$sLeft,$sOperator,$sRight,$sRightB) ;
			 	$nResponse = $aDlg->DoDialog() ;
			 	if( $nResponse!=Gtk::RESPONSE_OK )
			 	{
			 		return ;
			 	}
	 			
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_OPERATOR,  $aDlg->GetOperator() ) ;
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_LEFT,  $aDlg->GetSide('Left') ) ;
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_RIGHT,  $aDlg->GetSide('Right') ) ;
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_RIGHT_B,  $aDlg->GetSide('RightB') ) ;
			 	$aUICtrl->SetCellData($aItem, TreeDBTableLink::CLM_EXPRESSION,  $aDlg->GetExpression() ) ;
	 	}
	 }

	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @return	void
	  */
	 public function OnDelete()
	 {
	 	$aUICtrl = $this->GetUICtrl('TreeDBTableLink') ;
	 	JCAT_ASSERT::ASSERT_INSTANCE($aUICtrl,'TreeDBTableLink') ;
	 	
	 	$aItem = $aUICtrl->GetFirstSelectedItem() ;
	 	if(!$aItem)
	 	{
	 		JCAT_Gtk::MsgDlg(JCAT_Language::Sentence('请选择项目')) ;
	 		return ;
	 	}
	 	
	 	$aUICtrl->RemoveItem($aItem) ;
	 }
	 
	 /**
	  * what's this
	  * 
	  * @access	public
	  * @param	$arrTableColumns	array			what's this
	  * @return	void
	  */
	 public function SetTableColumns($arrTableColumns)
	 {
	 	$this->arrTableColumns = $arrTableColumns ;
	 }
	 private $arrTableColumns = array() ;
	 
	 /**
	  * 
	  * 
	  * @access	private
	  * @var	bool
	  */
	 private $bTableLink = true ;
	 
	 /**
	  * 
	  * 
	  * @access	private
	  * @var	string
	  */
	 private $sDataExchangeName ;
}

?><?
/**
 * [注意!!]
 *	以下内容由 JCAT PHP Toolbox 自动维护，手动更改的内容会被 JCAT PHP Toolbox 抹除，
 *	同时还可能破坏格式，导致 JCAT PHP Toolbox 无法正常读取。
 */
/*<<[UnmodifiableBlock.Start]::Coder Dialog Data::>>&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
<<{{DocumentClass:ViewGtkDoc}}>>
eCVEQSU5RFQlREJuJURCOCUxMCU3RF8lQTAlMUZRJTdGJTQwJTI1JURGJUQwVC0lMEElRDglOTQlOTQlOEElMEQlQTUlQzglMTIlRTl1JTVFJTBBJUM1JTI2bFolQjQlOTUlQjUlMTUlQzhWJUUwJTdGJURGQyUzQU4lQjNoJUI2WCVFQyUwMzElRTQlQ0MlRTFwJUNFJTk5JTkxJTBBJUFGJUU3JTNEJUVEJUJEJTgxJUQ3
JUYxJThCJUJBJUU4JTdDLiVCQyU4RiVFNiVEQyVFRCU3QiUxRCVBMWRDdCVCMSVERiVDNyVDNUZ2JTNFJUMzJUQ5JUYzJTNBJTk0JThDJUYyJTFGJTI2ciU1RCU5NyVDNnd1JUM2JUREJTE2JUY1JUNBQiVEQyU4RiU1RSVDN1lVJTFCJUU5JTE0WkolRTd2VyVBRCVFNSVCQ3YlQTglMjRFJUVEJURDJTdFJUJCJUNEJUFC
SiVERlclMDclQzclMjYlOTYlN0IlODdUJTBCJUI5cyVGQ2olRkUlQjglOTElREIlREElRjElQzclQUYlQjZ5cSVBRiVFNSU4RCVEQSU5NiVDRSVEQyVBMCUzRiVCQyVGMiU5ODclM0YlM0MlQUMlMUUlNUUlOTUlRjBSJUU1JTEwJTVDJUZFJT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